package com.cn.xly2023.controller;

import com.cn.xly2023.pojo.GoodType;
import com.cn.xly2023.pojo.PageBean;
import com.cn.xly2023.pojo.Result;
import com.cn.xly2023.service.GoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodtype")
public class GoodTypeController {

    @Autowired
    private GoodTypeService goodTypeService;

    //查询所有
    @GetMapping
    public Result getAllList(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             String typeName,Integer status,Integer ptypeId) {
        PageBean goodTypes = goodTypeService.selectAll(page,pageSize,typeName,status,ptypeId);
        return Result.success(goodTypes);
    }

    @GetMapping("/getPTypeList")
    public Result getAllPType(){
        List<GoodType> goodTypes = goodTypeService.getAllPType();
        return Result.success(goodTypes);
    }

//    //查询通过商品类型名
//    @GetMapping
//    public Result getBygoodTypeList(String typeName){
//        List<GoodType> goodTypeList=goodTypeService.selectByType(typeName);
//        return Result.success(goodTypeList);
//    }

    @DeleteMapping("/{typeId}")
    public Result getDeleteById(@PathVariable Integer typeId) {
        goodTypeService.deleteById(typeId);
        return Result.success();
    }

    //增加
    @PostMapping
    public Result getInsert(@RequestBody GoodType goodType) {
        List<GoodType> goodTypeList = goodTypeService.insert(goodType);
        return Result.success(goodTypeList);
    }

    //查询通过状态
    public Result getStatus(Integer status) {
        List<GoodType> goodTypeList = goodTypeService.selectByStatus(status);
        return Result.success(goodTypeList);
    }

    //修改
    @PutMapping
    public Result getUpateByTypeName(@RequestBody GoodType goodType) {
        List<GoodType> goodTypes = goodTypeService.updateByTypeName(goodType);
        return Result.success(goodTypes);
    }
}
